# Maintainer: George Rawlinson <grawlinson@archlinux.org>
# Contributor: Thorben Günther <echo YWRtaW5AeGVucm94Lm5ldAo= | base64 -d>

pkgname=hut
pkgver=0.4.0
pkgrel=1
pkgdesc='A CLI tool for Sourcehut'
arch=('loong64' 'x86_64')
url='https://sr.ht/~emersion/hut'
license=('AGPL3')
depends=('glibc')
makedepends=('git' 'go' 'scdoc')
options=('!lto' '!debug')
_commit='0185135be514f389114f84644383b65e9c7ccb4e'
source=("git+https://git.sr.ht/~emersion/hut#commit=$_commit")
sha256sums=('SKIP')

pkgver() {
  cd "$pkgname"

  git describe --tags | sed 's/^v//'
}

prepare() {
  cd "$pkgname"

  # download dependencies
  go mod download
}

build() {
  cd "$pkgname"

  # set Go flags
  export CGO_LDFLAGS="${LDFLAGS}"
  export CGO_CFLAGS="${CFLAGS}"
  export CGO_CPPFLAGS="${CPPFLAGS}"
  export CGO_CXXFLAGS="${CXXFLAGS}"
  export GOFLAGS="-buildmode=pie -trimpath -ldflags=-linkmode=external -mod=readonly -modcacherw"

  make --environment-overrides
}

check() {
  cd "$pkgname"

  go test -v ./...
}

package() {
  cd "$pkgname"

  make PREFIX=/usr DESTDIR="$pkgdir" install
}
